package ibm.cognos.imt.template

import groovy.xml.MarkupBuilder
import ibm.cognos.imt.Table
import groovy.xml.XmlUtil

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 5/14/14
 * Time: 10:20 AM
 * To change this template use File | Settings | File Templates.
 */
class TableTemplate extends AbstractTemplate {
    def Table table

    TableTemplate(t){
        table = t
    }

    def rowTemplate = '''
        <tableRow>
            <tableCells/>
        </tableRow>
'''
    def cellTemplate = '''
        <tableCell>
            <contents/>
        </tableCell>
'''
    def cellNode = new XmlSlurper().parseText(cellTemplate)


    @Override
    def generateTemplateSpec(MarkupBuilder builder) {
        builder.table {
            style {
                defaultStyles {
                    defaultStyle(refStyle: "tb")
                }
            }
            tableRows ()
        }
    }

    @Override
    def getTemplateNode() {
        root = new XmlSlurper().parseText(getSpecStr())
        table.cells.each{  row ->
            def rowNode = new RowTemplate().getTemplateNode()
            row.each{ cell ->
                def cellNode = new CellTemplate(cell).getTemplateNode()
                rowNode.tableCells.appendNode(cellNode)
            }
            root.tableRows.appendNode(rowNode)
        }
        root
    }

    def serializeNode(node) {
        def wr = new StringWriter()
        XmlUtil.serialize()
    }
}





